package com.zy.socket.exampls;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @Author Gong
 * @Description 1.客户端发送内容给服务端，服务端将内容打印到控制台上。
 * @dATE 2021/12/16 11:01
 **/
public class Client1 {
    public static void main(String[] args) {
        OutputStream outputStream =null;
        Socket socket =null;
        try {
            socket = new Socket(InetAddress.getByName("127.0.0.1"),8989);
             outputStream = socket.getOutputStream();
            outputStream.write("我是客户端".getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
